#include <nixonbot/core/bncs/protocol/Header.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

int Header::size()
{
	return sizeof(d->startByte) + sizeof(d->messageId) + sizeof(d->packetLen);
}

QDataStream& operator>> (QDataStream& in, Header& data)
{
	int bo = in.byteOrder();
	in.setByteOrder(QDataStream::LittleEndian);

	in >> data.d->startByte;
	in >> data.d->messageId;
	in >> data.d->packetLen;

	in.setByteOrder((QDataStream::ByteOrder)bo);
	return in;
}

QDataStream& operator<< (QDataStream& out, const Header& data)
{
	int bo = out.byteOrder();
	out.setByteOrder(QDataStream::LittleEndian);

	out << startByte;
	out << messageId;
	out << packetLen;

	out.setByteOrder((QDataStream::ByteOrder)bo);
	return out;
}

}
}
}
}

